package com.gui.mvc.demo;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

public class LoginController {
    @RequestMapping("/toLogin.do")
    public String toLogin() {
        System.out.println(
                "LoginController的toLogin方法");
        return "login";
    }

    @RequestMapping("/login.do")
    public String checkLogin(
            HttpServletRequest request) {
        System.out.println("LoginController"
                + "的checkLogin方法");

        String username =
                request.getParameter("username");
        String pwd =
                request.getParameter("pwd");
        System.out.println(username + " " + pwd);

        if("Tom".equals(username) &&
                "test".equals(pwd)) {
            //登录成功
            /*
             * 如果视图名前面添加有"redirect:",
             * DispatcherServlet会重定向。
             */
            return "redirect:toWelcome.do";
        }else {
            //登录失败
            request.setAttribute("login_failed",
                    "用户名或密码错误");
            return "login";
        }
    }





    @RequestMapping("/toWelcome.do")
    public String toWelcome(){
        return "welcome";
    }
}


